﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using hbse.Entities;
using NHibernate;
using hbse.DTO;

namespace hbse.Service 
{
    public class AddOrderService
    {
        public List<hbse.DTO.ProductDTOAddOrder> searchByCode(string _productCode, ISession session)
        {

            List<ProductDTOAddOrder> productDTOAddOrders = new List<ProductDTOAddOrder>();
            ProductDTOAddOrder productDTOAddOrder = null;

            using (session.BeginTransaction())
            {

                 var products = session.CreateQuery("from Product p where p.ProductCode like '%" + _productCode + "%'").Future<Product>();
                foreach (Product p in products){
                    productDTOAddOrder = new ProductDTOAddOrder();
                    productDTOAddOrder.Id = p.Id;
                    productDTOAddOrder.ProductCode = p.ProductCode;
                    productDTOAddOrder.CustomerCode = p.Customer.CustomerCode;
                    productDTOAddOrders.Add(productDTOAddOrder);
                }
                
            }
            
            return productDTOAddOrders;
        }

        public AddOrderDTO getByProductId(string _productCode, ISession session)
        {
          
            AddOrderDTO addOrderDTO = new AddOrderDTO();
            Product product = new Product();

            using (session.BeginTransaction())
            {
                var products = session.CreateQuery("from Product p where p.ProductCode ='" + _productCode + "'").Future<Product>();
                product = products.First();

                addOrderDTO.ProductCode = product.ProductCode;
                //addOrderDTO.SaleOrder = order.SaleOrder;
                //addOrderDTO.MRPNo = order.MrpNo;
                //addOrderDTO.QtyOrder = order.QtyOrder;
                //addOrderDTO.FGStock = order.FgStock;
                //addOrderDTO.Qty = order.QtyProduction;
                //addOrderDTO.Price = order.Price;
                //addOrderDTO.Barcode = order.Barcode;

            }


            return addOrderDTO;
        }

    }
}
